package app.common.utils.cjt.ao;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 找到凭证列表响应对象
 * @author feizns
 * @since 2023/05/12
 */
@NoArgsConstructor
@Data
public class FindVoucherListVo {

    /**
     * totalCount
     */
    private Integer totalCount;

    /**
     * totalPageNum
     */
    private Integer totalPageNum;

    /**
     * columns
     */
    private List<String> columns;

    /**
     * rows
     */
    private List<List<String>> rows;

    /**
     * 获得列数据
     * @param column 列
     * @return {@link List}<{@link String}>
     */
    public List<String> getColumnData(String column) {
        int columnIndex = getColumnIndex(column);
        return columnIndex == -1
                ? Collections.emptyList()
                : rows.stream().map(item -> item.get(columnIndex)).collect(Collectors.toList());
    }

    /**
     * 获得列索引
     * @param column 列
     * @return int
     */
    public int getColumnIndex(String column) {
        return columns != null ? columns.indexOf(column) : -1;
    }

}
